Introduction:
This project aims to analyze and visualize heart disease data to uncover patterns and insights related to age, cholesterol levels, maximum heart rate, and resting blood pressure. The analysis includes creating histograms and heatmaps to highlight correlations and trends within the dataset.
import pandas as pd
data = pd.read_csv("/Users/Shared/Python/HeartDiseaseTrain-Test.csv")
print(data.info())
print(data.describe())
import matplotlib.pyplot as plt
import pandas as pd
data = pd.read_csv("/Users/Shared/Python/HeartDiseaseTrain-Test.csv")
age = data['age']
cholesterol = data['cholestoral']
plt.figure(figsize=(10, 6))
plt.hist(cholesterol, bins=30, color='skyblue', edgecolor='black')
plt.title('Distribution of Cholesterol Levels')
plt.xlabel('Cholesterol')
plt.ylabel('Frequency')
plt.grid(True)
plt.show()
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
data = pd.read_csv("/Users/Shared/Python/HeartDiseaseTrain-Test.csv")
resting_blood_pressure = data['resting_blood_pressure']
Max_heart_rate = data['Max_heart_rate']
plt.figure(figsize=(10, 6))
plt.imshow(np.array([resting_blood_pressure, Max_heart_rate]), cmap='hot', aspect='auto')
plt.title('Heatmap of Resting Blood Pressure and Max Heart Rate')
plt.ylabel('Resting Blood Pressure')
plt.xlabel('Max Heart Rate')
plt.colorbar()
plt.show()
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
data = pd.read_csv("/Users/Shared/Python/HeartDiseaseTrain-Test.csv")
fig, axs = plt.subplots(1, 3, figsize=(18, 6))
resting_blood_pressure = data['resting_blood_pressure']
Max_heart_rate = data['Max_heart_rate']
# Hot colormap
axs[0].imshow(np.array([resting_blood_pressure, Max_heart_rate]), cmap='hot', aspect='auto')
axs[0].set_title('Hot Colormap')
axs[0].axis('off')
# Cool colormap
axs[1].imshow(np.array([resting_blood_pressure, Max_heart_rate]), cmap='cool', aspect='auto')
axs[1].set_title('Cool Colormap')
axs[1].axis('off')
# Viridis colormap
axs[2].imshow(np.array([resting_blood_pressure, Max_heart_rate]), cmap='viridis', aspect='auto')
axs[2].set_title('Viridis Colormap')
axs[2].axis('off')
plt.tight_layout()
plt.show()
Insights and Findings:
Cholesterol Distribution: The histogram shows that middle-aged individuals have a higher frequency of elevated cholesterol levels, whereas older individuals tend to have higher cholesterol levels overall.
Correlation Analysis: The heatmap indicates a visual correlation between resting blood pressure and maximum heart rate, allowing for a better understanding of how these variables interact.
Enhanced Visualizations: The comparative heatmaps with different color schemes provide multiple perspectives on the data, making it easier to identify patterns and outliers.
Conclusion:
This project provides a detailed analysis and visualization of heart disease data, highlighting key patterns and relationships between age, cholesterol levels, maximum heart rate, and resting blood pressure. The use of histograms and heatmaps allows for a clear and intuitive presentation of the data, facilitating better understanding and interpretation of the results.